window.onload = function () {

}


function getIndentList() {
    $.post("/indentListGET", {
        userNo: $("#userNo").val(),
        indentDate: $("#indentDate").val()
    }, function (res, status) {
        //console.log(res)
        if (res.data.indentListData === null) {
            alert("未查询到相关信息");
            return
        }
        let tableList = document.getElementsByClassName("queryIndentTable")
        tableList[0].innerHTML = '' +
            '<thead><tr>' +
            '<th scope="col">订单号</th>' +
            '<th scope="col">订货时间</th>' +
            '<th scope="col">订单总金额</th>' +
            '<th scope="col">折扣率</th>' +
            '<th scope="col">实际支付金额</th>' +
            '<th scope="col">明细</th>' +
            '</tr></thead>'
        tableList[0].innerHTML += addIndentListToHTML(res.data.indentListData)

    })
}

//addIndentListToHTML 添加订单表至页面
function addIndentListToHTML(data) {
    let s = '<tbody>'
    for (let i = 0; i < data.length; ++i) {
        s += '' +
            '<tr>' +
            '<th scope="row" class="goodNo">' + data[i].IndentNo + '</th>' +
            '<td>' + data[i].IndentDate.String + '</td>' +
            '<td>' + data[i].IndentTotalPrice + '</td>' +
            '<td>' + data[i].IndentDiscount + '</td>' +
            '<td>' + data[i].IndentRealPrice + '</td>' +
            '<td>' + '<a href="javascript:void(0)" onclick="getIndentDetail(' + data[i].IndentNo + ')" class="indentDetail" data-toggle="modal" data-target="#exampleModal">订单明细</a>' + '</td>' +
            '</tr>';
    }
    s += '</tbody>';
    return s;
}

//getIndentDetail 获取订单明细
function getIndentDetail(indentNo) {
    $.post("/indentDetail", {
        indentNo: indentNo
    }, function (res, status) {
        console.log(res);
        let consignmentInfo = document.getElementsByClassName("queryUserTable")
        consignmentInfo[0].innerHTML =
            '' +
            '<thead><tr>' +
            '<th scope="col">用户号' + res.data.consignmentInfo.UserNo + '</th>' +
            '<th scope="col">' + res.data.consignmentInfo.UserName.String + '</th>' +
            '<th scope="col">' + res.data.consignmentInfo.ConsignmentName.String + '</th>' +
            '</tr></thead>';
        let indentDetailTable = document.getElementsByClassName("indentDetail-warp");
        indentDetailTable[0].innerHTML = '' +
            '<thead><tr>' +
            '<th scope="col">商品号</th>' +
            '<th scope="col">商品名</th>' +
            '<th scope="col">单价</th>' +
            '<th scope="col">所需个数</th>' +
            '<th scope="col">预计到货日期</th>' +
            '</tr></thead>';
        indentDetailTable[0].innerHTML += addIndentDetailToHTML(res.data.deliveryDetailList);
    })
}

//addIndentDetailToHTML 添加订单明细至模态框
function addIndentDetailToHTML(deliveryDetailList) {
    let s = '<tbody>'
    for (let i = 0; i < deliveryDetailList.length; ++i) {
        s += '' +
            '<tr>' +
            '<th scope="row" class="goodNo">' + deliveryDetailList[i].GoodNo + '</th>' +
            '<td>' + deliveryDetailList[i].GoodName.String + '</td>' +
            '<td>' + deliveryDetailList[i].GoodPrice + '</td>' +
            '<td>' + deliveryDetailList[i].GoodNum + '</td>' +
            '<td>' + deliveryDetailList[i].GoodDeliveryDate.String + '</td>' +
            '</tr>';
    }
    s += '</tbody>';
    return s;
}